package com.hlmc.spider;

import com.hlmc.dao.DS_detailDao;
import com.hlmc.entity.DS360_dt;
import com.hlmc.util.Atool;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import javax.annotation.Resource;
import java.util.Map;

@Service("ds_pipeline")
public class DS_pipeline implements Pipeline {

    @Resource
    private DS_detailDao dtDao;

    @Override
    public void process(ResultItems resultItems, Task task) {

        Map<String, Object> mapResults = resultItems.getAll();
        if (mapResults != null) {

            mapResults.put("id", 0);
        }

        try {
            DS360_dt dt = (DS360_dt) Atool.mapToObject(mapResults, DS360_dt.class);

            if (dt.getTitle() != null) {

                dtDao.add(dt);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
